package com.dingding.commonservice.core.company.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.dingding.common.core.base.daox.ISQLBaseDao;
import com.dingding.common.core.beans.Organization;
import com.dingding.commonservice.core.city.sql.CitySQL;
import com.dingding.commonservice.core.company.dao.ICompanyDao;
import com.dingding.commonservice.core.company.sql.CompanySQL;
import com.dingding.facade.commonservice.common.dto.city.ResOpenCityDTO;
import com.dingding.facade.commonservice.common.dto.company.ResGetCompanyListDTO;

/**
 * 
 * @ClassName: CompanyDaoImpl 
 * @Description: 公司DAO实现类
 * @author YHQ
 * @date 2016年12月1日 下午6:11:57
 * @since V2.5.7
 * 
 */
@Component("companyDao")
public class CompanyDaoImpl implements ICompanyDao{

	@Resource(name = "SQLBaseDao")
	private ISQLBaseDao sqlBaseDao;
	
	private Logger log = Logger.getLogger(this.getClass());
	/**
	 * 
	 * @Title: getCompanyListDTOs 
	 * @Description: 根据城市Id获取公司列表
	 * @param cityId 城市Id
	 * @author YHQ 
	 * @since V2.5.7
	 * @return List<ReqGetCompanyListDTO>    返回类型
	 * 
	 */
	@Transactional(readOnly = true)
	public List<ResGetCompanyListDTO> getCompanyListDTOs(Integer cityId) {
		
		try {
			return sqlBaseDao.listSqlToCustomBean(ResGetCompanyListDTO.class, CompanySQL.GET_COMPANY_LIST, cityId);
		} catch (Exception e) {
			log.error("根据城市Id获取公司列表时出现异常   类：" + this.getClass() + "getCompanyListDTOs()", e);
		}
		
		return null;
	}
	
	@Override
	@Transactional(readOnly = true)
	public ResGetCompanyListDTO getCompanyDTOById(Integer organizationId) {
		
		try {
			return sqlBaseDao.sqlToCustomBeanUnique(ResGetCompanyListDTO.class, CompanySQL.GET_COMPANY_BY_ID, organizationId);
		} catch (Exception e) {
			log.error("根据公司Id获取公司时出现异常   类：" + this.getClass() + " geCityDTOs()", e);
		}
		return null;
	}

	/**
	 * 
	 * @Title: getOrganizationById 
	 * @Description: 根据organizationId查询公司详情
	 * @param  参数说明 
	 * @author hufan
	 * @return 返回类型 
	 * @throws
	 */
	@Override
	@Transactional(readOnly = true)
	public Organization getOrganizationById(Integer organizationId) {
		
		try {
			return sqlBaseDao.sqlToCustomBeanUnique(Organization.class, CompanySQL.GET_ORGANIZATION_DETAILS_BY_ID, organizationId);
		} catch (Exception e) {
			log.error("根据公司Id获取公司时出现异常   类：" + this.getClass() + " getOrganizationById()", e);
		}
		return null;
	}

	
}
